package cn.itsource.basic.service.Impl;

import cn.itsource.basic.mapper.BaseMapper;
import cn.itsource.basic.query.BaseQuery;
import cn.itsource.basic.service.IBaseService;
import cn.itsource.basic.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Override
    @Transactional
    public void save(T t) {

        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    @Transactional
    public void update(T t ) {
        baseMapper.update(t);
    }


    @Override
    public PageResult<T>  queryPage(BaseQuery query) {
        Long queryCount = baseMapper.queryCount(query);
        List<T> base = null;
        if(queryCount!=null||queryCount!=0){
            //查询页面的分页数据
            base = baseMapper.queryPage(query);
        }
        return new PageResult<>(queryCount,base);
    }

    @Override
    public void removes(List<Long> ids) {
        baseMapper.removes(ids);
    }
}